package feifei.second;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/deleteUser.action")
public class DeleteUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        //获取表单数据 id
        String id = req.getParameter("id");
        int uid = Integer.parseInt(id);
        HttpSession session = req.getSession();
        List<User> userList = (List<User>) session.getAttribute("user");
//        String username = req.getParameter("username");
//        ServletContext Context = this.getServletContext();
//        List<User> userList = (List<User>) Context.getAttribute("user");
        userList.remove(uid);//根据id删除
        //删除完再次放入session
        session.setAttribute("userList", userList);
        resp.sendRedirect(req.getContextPath() + "/homework/userInfo2.jsp");
//        for(int i=userList.size()-1;i>=0;i--){
//            if(userList.get(i).getUsername().equals(username)){
//                userList.remove(userList.get(i));
//            }
//        }

    }
}
